package chord.finder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import sun.reflect.ReflectionFactory.GetReflectionFactoryAction;

import com.juitar.base.Tuning;
import com.juitar.base.utils.Config;

/**
 * Servlet implementation class for Servlet: Options
 *
 */
 public class Options extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public Options() {
		super();
	}   	
	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}  	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String tuning = request.getParameter("tuning");
		List<Tuning> tunings = Config.getTunings();
		for (Tuning t : tunings) {
			if (t.getName().equalsIgnoreCase(tuning)) {
				HttpSession session = request.getSession();
				session.setAttribute("tuning", t);
				System.out.println("Selected tuning:" + t);
			}
		}
		
		RequestDispatcher dispatcher = request.getRequestDispatcher("/");
		dispatcher.forward(request, response);
		
	}   	  	    
}